package movee.api.v1;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import movee.cluster.ClusterInfo;
import movee.domain.api.SuccessResponse;
import movee.service.AppClusterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * restful controller层
 *
 * @author movee
 */
@RestController
@RequestMapping(value = "/v1/app/cluster", produces = "application/json")
@Slf4j
@Tag(name = "集群互通接口")
public class ApiAppClusterControllerV1 {

    private final AppClusterService appClusterService;

    public ApiAppClusterControllerV1(AppClusterService appClusterService) {
        this.appClusterService = appClusterService;
    }

    /**
     * 获取节点集群信息
     *
     * @return 节点集群信息
     */
    @Operation(summary = "获取节点集群信息")
    @GetMapping(value = "/info")
    public SuccessResponse<ClusterInfo> getClusterInfo() {

        return new SuccessResponse<>(appClusterService.getClusterInfo());
    }

    /**
     * 备份任务调度通知
     * @return success
     */
    @Operation(summary = "通知任务已调度")
    @PostMapping(value = "/event/task/scheduled")
    public SuccessResponse<String> notifyScheduledTask() {
        log.info("notifyScheduledTask invoked");
        appClusterService.notifyScheduledTask();
        return new SuccessResponse<>("success");
    }

}
